layui.define(['jquery','table','element'],function(exports){
	var $ = layui.$
	,table = layui.table
	,element = layui.element
	,obj = {
    	init: function(option){
			
			element.render();
			
			table.render({
				elem: '#dataList'
				,id : 'dataList'
				,url: MyUrl.memberJsonList
				,limit: MyConfig.pagesize
				,cols: [[
					{type:'checkbox'}
					,{field:'id', width:80, title: 'ID',align: 'center', sort: true}
					,{field:'username', minwidth:200, title: '登陆名',sort: true}
					,{field:'phone', minwidth:200, title: '手机号码',sort: true}
					,{field:'status', minwidth:50, title: '状态', templet: '#statusTpl' ,sort: true}
					,{field:'created', width:150, align: 'center', title: '注册时间', templet: '#createdTpl' , sort: true}
					,{field:'lastdate', width:150, align: 'center', title: '最后登陆时间', templet: '#createdTpl' , sort: true}
					,{toolbar:'#bar',width:300, align: 'center', title: '操作'}
				]]
				,page:{
					layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
					,limits : [15, 20, 30, 50]
					,curr: 1 //设定初始在第1页
					,groups: 5 //只显示 1 个连续页码
					,first: '首页' //不显示首页
					,last: '尾页' //不显示尾页
				}
			});
			
			table.on('tool(dataFilter)', function(obj){
				var data = obj.data;
				if(obj.event === 'del'){
					layer.confirm('确定要删除这一条记录？', function(index){
						window.location.href=MyUrl.memberDelete+data.id;	
					});
				} else if(obj.event === 'edit'){
					window.location.href=MyUrl.memberEdit+data.id;	
				} else if(obj.event === 'allow'){
					window.location.href=MyUrl.memberOpration+data.id+'/key/status/value/1';	
				} else if(obj.event === 'close'){
					window.location.href=MyUrl.memberOpration+data.id+'/key/status/value/0';	
				} else if(obj.event === 'reset'){
					window.location.href=MyUrl.memberOpration+data.id+'/key/password/value/999';	
				}
			});
			
			var $ = layui.$, active = {
				deleteData: function(){
					var checkStatus = table.checkStatus('dataList')
					,data = checkStatus.data
					,len=data.length
					,arr=[];
					if(len<1){
						layer.msg('没有选中任何记录！');
						return;
					}
					layer.confirm('确定要删除选择的记录？', function(){
						for(var i=0; i<len; i++){arr.push(data[i].id);}
						window.location.href=MyUrl.newsDelete+arr;	
					});
				}
				,addData(){
					window.location.href=MyUrl.newsAdd;	
				}
			};
		
			$('.demoTable .layui-btn').on('click', function(){
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});
				
		}
		
		
		
		
	};
	exports('member', obj);
});    